import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';

import '../../a_yyt/models/medical_elder_entity.dart';
import '../../model/activity/activity_model.dart';
import '../../net/response/activity/actvity_recommend_list_data.dart';
import '../../ui/select_multi_old_page.dart';
import 'activity_info_detal_view_model.dart';

class OldSignInViewModel extends BaseViewModel {
  final ActvityRecommendListData item;

  OldSignInViewModel(BuildContext context, this.item) : super(context);

  var contentList = <TitleValue>[];
  List<MedicalElderInfo> oldList = [];

  String get selectName => oldList.map((e) => e.name).join("，");

  var model = ActivityModel();

  void selectOld() {
    Go().push(SelectMulitOldPage((old) {
      oldList = old;
      notifyListeners();
    }));
  }

  @override
  void onCreated() {
    super.onCreated();
    contentList = [
      TitleValue(title: "活动名称：", value: "${item.activityName}"),
      TitleValue(title: "活动内容：", value: "${item.activityContent}", type: 1),
      TitleValue(
        title: "活动类型：",
        value: "${item.activityTypeName}",
      ),
      TitleValue(
        title: "活动开始时间：",
        value: "${item.activityStartTime}",
      ),
      TitleValue(
        title: "活动结束时间：",
        value: "${item.activityEndTime}",
      ),
      TitleValue(
        title: "活动负责人：",
        value: "${item.directorName}",
      ),
      TitleValue(
        title: "报名开始时间：",
        value: "${item.enrollStartTime}",
      ),
      TitleValue(
        title: "报名结束时间：",
        value: "${item.enrollEndTime}",
      ),
      TitleValue(
        title: "签到积分：",
        value: "${item.checkPoints}",
      ),
      TitleValue(
        title: "活动人数：",
        value: "${item.isLimitHumans == 1 ? "${item.limitHumans}" : "不限制"}",
      ),
      TitleValue(
        title: "志愿者积分：",
        value: "${item.volunteerPoints}",
      ),
      TitleValue(
        title: "志愿者人数：",
        value: "${item.limitVolunteers}",
      ),
      TitleValue(title: "备注：", value: "${item.remark}", type: 1),
    ];
    notifyListeners();
  }

  Future<void> submitEnroll() async {
    if (oldList.isEmpty) {
      showToast("请选择报名长者");
      return;
    }

    showLoadingDialog();
    try {
      await model.enrollActivity(
          activityId: item.id.toString(),
          humanType: "0",
          regClientType: "windows",
          activityNo: item.activityNo??"",
          activityName: item.activityName??"",
          joinHumanIds: oldList.map((e) => e.id.toString()).toList());
      hideDialog();
      showToast("长者报名成功");
      finish();
    } catch (e) {
      showToast(NetErrorUtils.getNetError(e));
      hideDialog();
    }
  }
}
